package com.modern.js.controller;

import com.modern.js.entity.Employee;
import com.modern.js.service.IEmployeeService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class PageController {

    @Autowired
    private IEmployeeService iEmployeeService;
    /**
     * 去到登录页面
     * @return
     */
    @GetMapping("/goLogin")
    public String goLogin(){
        return "login";
    }

    /**
     * 去到index页面
     * @return
     */
    @GetMapping("/")
    public String goIndex(){
//        model.addAttribute("employee",(Employee) SecurityUtils.getSubject().getPrincipal());
        return "index";
    }

    /**
     * 去到403页面，表示没有权限
     * @return
     */
    @GetMapping("/403")
    public String un(){
        return "403";
    }


    @GetMapping("/welcome")
    public String welcome(){
        return "welcome";
    }

    @GetMapping("/byName")
    public String goByName(Model model, HttpSession session){
        Employee employee = (Employee) session.getAttribute("employee");
        System.out.println("对象："+employee);
        model.addAttribute("employee",employee);
        return "personage";
    }
}
